﻿#region summary

// Copyright (c)  MOKEYISH. All rights reserved.
// Licensed under the MIT License, See License.txt in the project root for license information.

#endregion

namespace NSQL.Expressions
{
    public class LikeExpression : BaseExpression, ILikeExpression
    {
        public IExpression LeftExpression { get; set; }
        public StringExpression PatternExpression { get; set; }

        public bool IsStartsWith => HasPattern && PatternExpression.Value.StartsWith("%");
        public bool IsEndsWith => HasPattern && PatternExpression.Value.EndsWith("%");
        public bool IsContains => IsStartsWith && IsEndsWith;

        public bool HasPattern => PatternExpression?.Value != null;

        public LikeExpression()
        {
        }

        public LikeExpression(IExpression leftExpression, StringExpression patternExpression)
        {
            LeftExpression = leftExpression;
            PatternExpression = patternExpression;
        }

        public override T Accept<T>(IExpressionVisitor<T> visitor) => visitor.Visit(this);
    }
}